<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>默认行为的阻止</title>
        <style>
            *{margin: 0;padding:0;box-sizing: border-box}
            .container{
                /* 1vh  等于视口高度的 1% */
                height: 100vh;
            }
        </style>
    </head>
    <body>
        <div class="container">
            <h2>测试</h2>
            <a href="http://www.baidu.com">百度</a>
            <input type="text">
            <p>ssfwefwefwefawefwafeewaefawfwafwafe</p>
        </div>
        <script>
            //获取元素
            const container = document.querySelector('.container');

            container.addEventListener('touchstart', function(e){
                //阻止默认行为
                e.preventDefault();
            });

            //获取 a 元素
            const a = document.querySelector('a');
            const input = document.querySelector('input');
            const p = document.querySelector('p');
            a.addEventListener('touchstart', function(e){
                //阻止冒泡
                e.stopPropagation();
            })

            input.addEventListener('touchstart', function(e){
                //阻止冒泡
                e.stopPropagation();
            })

            p.addEventListener('touchstart', function(e){
                //阻止冒泡
                e.stopPropagation();
            })
        </script>
    </body>
</html>
